package org.hyl.javabase.model;

//������ģʽ
public class VisitorDemo {
	public static void main(String[] args) {

		Visitor visitor = new MyVisitor1();
		Subject2 sub = new MySubject2();
		sub.accept(visitor);
	}
}

interface Visitor {
	public void visit(Subject2 sub);
}

class MyVisitor1 implements Visitor {

	public void visit(Subject2 sub) {
		System.out.println("visit the subject��" + sub.getSubject());
	}
}

interface Subject2 {
	public void accept(Visitor visitor);

	public String getSubject();
}

class MySubject2 implements Subject2 {

	public void accept(Visitor visitor) {
		visitor.visit(this);
	}

	public String getSubject() {
		return "love";
	}

}